﻿using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

namespace Dora.Tools.Utility
{
    public static class HttpExtensions
    {
        public static async Task<string> GetStringAsync(this Uri uri)
        {
            var client = new HttpClient();
            return await client.GetStringAsync(uri);
        }

        public static async Task<Stream> GetStreamAsync(this Uri uri)
        {
            var client = new HttpClient();
            return await client.GetStreamAsync(uri);
        }

        public static async Task<byte[]> GetBytesAsync(this Uri uri)
        {
            var client = new HttpClient();
            return await client.GetByteArrayAsync(uri);
        }

        public static string GetString(this Uri uri)
        {
            var client = new HttpClient();
            return client.GetStringAsync(uri).Result;
        }

        public static Stream GetStream(this Uri uri)
        {
            var client = new HttpClient();
            return client.GetStreamAsync(uri).Result;
        }

        public static byte[] GetBytes(this Uri uri)
        {
            var client = new HttpClient();
            return client.GetByteArrayAsync(uri).Result;
        }
    }
}
